/*
 * @Author: DUST
 * @Date: 2023-05-16 15:57:10
 * @LastEditors: DUST
 * @LastEditTime: 2023-05-16 15:57:14
 * @FilePath: \vite-project\src\utils\time.ts
 * @Description: 
 * undefined
 */
import moment, { Moment } from "moment";
/**
 * 时间格式化
 * @param timeStr 时间戳,字符串
 * @param format 格式化类型
 */
const timeFormat = (
  timeStr?: string | number | null | Moment,
  format:
    | string
    | "YYYY-MM-DD"
    | "YYYY-MM"
    | "YYYY-MM-DD HH:mm:ss"
    | "HH:mm"
    | "HH:mm:ss" = "YYYY-MM-DD"
): string => {
  if (timeStr) {
    return moment(timeStr).format(format);
  }
  return "";
};

export default timeFormat;